package com.fishbone.core.boot;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.ansi.AnsiStyle;
import org.springframework.core.env.Environment;

import java.io.PrintStream;

/**
 * @ClassName FishBoneBanner
 * @Author huyaxi
 * @DATE 2020/4/23 14:52
 */
public class FishBoneBanner implements Banner {


    private static final String[] BANNER = { "",
            "  ___________.__         .__    __________                        _________  .__                      .___\\",
            "        \\_   _____/|__|  ______|  |__ \\______   \\  ____    ____    ____ \\_   ___ \\ |  |    ____   __ __   __| _/\\" ,
            "         |    __)  |  | /  ___/|  |  \\ |    |  _/ /  _ \\  /    \\ _/ __ \\/    \\  \\/ |  |   /  _ \\ |  |  \\ / __ | \\" ,
            "         |     \\   |  | \\___ \\ |   Y  \\|    |   \\(  <_> )|   |  \\\\  ___/\\     \\____|  |__(  <_> )|  |  // /_/ | \\" ,
            "         \\___  /   |__|/____  >|___|  /|______  / \\____/ |___|  / \\___  >\\______  /|____/ \\____/ |____/ \\____ | \\" ,
            "             \\/             \\/      \\/        \\/              \\/      \\/        \\/                           \\/ "};

    private static final String SPRING_BOOT = " :: FishBone Cloud :: ";

    private static final int STRAP_LINE_SIZE = 42;

    @Override
    public void printBanner(Environment environment, Class<?> sourceClass, PrintStream printStream) {
        for (String line : BANNER) {
            printStream.println(line);
        }
        String version = SpringBootVersion.getVersion();
        version = (version != null) ? " (v" + version + ")" : "";
        StringBuilder padding = new StringBuilder();
        while (padding.length() < STRAP_LINE_SIZE - (version.length() + SPRING_BOOT.length())) {
            padding.append(" ");
        }

        printStream.println(AnsiOutput.toString(AnsiColor.GREEN, SPRING_BOOT, AnsiColor.DEFAULT, padding.toString(),
                AnsiStyle.FAINT, version));
        printStream.println();
    }
}
